﻿Imports System.Windows.Forms

Public Class FrmOptions

    Public Event SETTINGSSAVED()

    Private Sub CmbRefresh_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Lblms.Visible = False
        Txtms.Visible = False
        LblRefreshEvery.Visible = False
        Select Case CmbRefresh.SelectedIndex
            Case Is = 0
                Txtms.Text = 300
            Case Is = 1
                Txtms.Text = 500
            Case Is = 2
                Txtms.Text = 1500
            Case Is = 3
                Txtms.Text = 3000
            Case Is = 4
                Txtms.Text = 0
            Case Is = 5
                Lblms.Visible = True
                Txtms.Visible = True
                LblRefreshEvery.Visible = True
        End Select
    End Sub

    
    Private Sub FrmOptions_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TabCtrlOptions.TabPages.Remove(TabUpdates)
        My.Settings.Reload()
        Select Case My.Settings.Refresh
            Case Is = 0
                CmbRefresh.SelectedIndex = 4
            Case Is = 300
                CmbRefresh.SelectedIndex = 0
            Case Is = 800
                CmbRefresh.SelectedIndex = 1
            Case Is = 1500
                CmbRefresh.SelectedIndex = 2
            Case Is = 3000
                CmbRefresh.SelectedIndex = 3
            Case Else
                CmbRefresh.SelectedIndex = 5
                Txtms.Text = My.Settings.Refresh
        End Select
        ChkAutoFinishJob.Checked = My.Settings.Auto_SaveToFile
        ChkShutDown.Checked = My.Settings.AlwaysShutDown
        ChkNotification.Checked = My.Settings.Warn_Errors
    End Sub

    Private Sub CmdOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOk.Click
        If CmbRefresh.SelectedIndex = 5 Then
            If IsNumeric(Txtms.Text) = False Then
                Err.SetIconAlignment(Txtms, ErrorIconAlignment.MiddleRight)
                Err.SetIconPadding(Txtms, 2)
                Err.BlinkRate = 1000
                Err.BlinkStyle = ErrorBlinkStyle.AlwaysBlink
                Err.SetError(Txtms, "This is not a numeric value")
                Exit Sub
            End If
        End If
        My.Settings.Refresh = Txtms.Text
        My.Settings.Auto_SaveToFile = ChkAutoFinishJob.Checked
        My.Settings.AlwaysShutDown = ChkShutDown.Checked
        My.Settings.Warn_Errors = ChkNotification.Checked
        My.Settings.Save()
        My.Settings.Reload()
        RaiseEvent SETTINGSSAVED()
        Me.Close()
    End Sub

    Private Sub CmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdCancel.Click
        Me.Close()
    End Sub
End Class
